﻿package mortal.game.view.achievement.item
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.gengine.resource.info.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.achievement.data.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class AchievementPreFinishCell extends GSprite
    {
        private var _bg:GBitmap;
        private var _itemPic:GBitmap;
        private var _proTxt:GTextFiled;
        private var _typeInfo:SAchievementType;

        public function AchievementPreFinishCell()
        {
            this.buttonMode = true;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.bitmap(ImagesConst.AchievementUpcomCellBg, 0, 0, this);
            this._itemPic = UIFactory.bitmap("", 28, 20, this);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = AlignMode.CENTER;
            this._proTxt = UIFactory.gTextField("", 0, 75, 96, 75, this, _loc_1);
            this._proTxt.multiline = true;
            this._proTxt.wordWrap = true;
            this.configEventListener(MouseEvent.CLICK, this.onMouseCk);
            this.configEventListener(MouseEvent.ROLL_OVER, this.overHd);
            this.mouseEnabled = true;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._typeInfo = null;
            this._bg.dispose(param1);
            this._bg = null;
            this._itemPic.dispose(param1);
            this._itemPic = null;
            this._proTxt.dispose(param1);
            this._proTxt = null;
            return;
        }// end function

        public function updateCell(param1:SAchievementType) : void
        {
            var _loc_2:SAchievement = null;
            var _loc_3:TAchievement = null;
            var _loc_4:TAchievementType = null;
            this._typeInfo = param1;
            if (this._typeInfo.curAchievements.length > 0)
            {
                _loc_2 = this._typeInfo.curAchievements[0];
                _loc_3 = AchievementConfig.instance.achievementObj[_loc_2.id];
                if (_loc_3)
                {
                    this._proTxt.htmlText = "" + _loc_3.title + "\n" + _loc_2.curProcess + "/" + _loc_3.achievementProcess;
                }
            }
            this._itemPic.visible = true;
            if (this._itemPic.bitmapData)
            {
                this._itemPic.bitmapData = null;
            }
            _loc_4 = AchievementConfig.instance.typeObj[_loc_3.typeId];
            if (_loc_4)
            {
                LoaderManager.instance.load(_loc_4.icon + ".jpg", this.onLeftItemLoad, LoaderPriority.LevelB);
            }
            return;
        }// end function

        private function onLeftItemLoad(param1:ImageInfo) : void
        {
            if (this._itemPic && param1.bitmapData)
            {
                this._itemPic.bitmapData = param1.bitmapData;
                this._itemPic.width = 37;
                this._itemPic.height = 39;
            }
            return;
        }// end function

        private function onMouseCk(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.AchievementUpcomingBtnCk, this._typeInfo));
            return;
        }// end function

        private function overHd(event:MouseEvent) : void
        {
            this.configEventListener(MouseEvent.MOUSE_OUT, this.outHd);
            this.filters = [FilterConst.chatTipsFilter];
            return;
        }// end function

        private function outHd(event:MouseEvent) : void
        {
            this.removeEventListener(MouseEvent.MOUSE_OUT, this.outHd);
            this.filters = null;
            return;
        }// end function

    }
}
